feat(server): add trackExposure - #209
Merged
feugy merged 2 commits intoAug 26, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dferber90
approved these changes
Aug 26, 2026
feugy
deleted the
damienfeugas/exp-3368-port-trackexposure-from-toolkit-to-analytics
branch
August 26, 2026 15:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🖖 What's in there?
Ports
trackExposure()from the@vercel/toolkitprototype to@vercel/analytics/server, so vercel-marketing can report experiment exposures from a canary release.It posts to
/_vercel/insights/exposure, whichapi-analytics-ingestionalready serves as an alias of/v1/eventtaggedt: 'exposure'.userId,groupIdandpropsgo top-level, matching the fields that service reads and its 256-char truncation.Server-side only. Browser exposure tracking is a separate ticket.
Landing it meant
trackandtrackExposureshared five near-identical blocks, so the request plumbing now lives inserver/request.ts:rejectBrowserRuntime()— thetypeof windowguardresolveEndpoint('event' | 'exposure')— addsVERCEL_WEB_ANALYTICS_EXPOSURE_ENDPOINT, and treatsVERCEL_WEB_ANALYTICS_ENDPOINTas a base URL for exposures while keeping it verbatim for eventsreportMissingEndpoint()— the dev/prod logging when no endpoint resolvesdispatch()— request context, header forwarding, the shared envelope, the POST, and the catch-alltrackdropped from 84 to 30 lines with no behaviour change:server/index.test.tsis untouched and still green. The server bundle went 8.03 → 7.41 KB.🤺 How to test?
src/server/index.test.tsis deliberately unmodified — it is the guardrail proving thetrackrefactor is behaviour-preserving.🔬 Notes to reviewers
Two intentional behaviour changes:
track's browser-guard message said@vercel/web-analytics/server, which is not an importable path. Sharing the guard forced one string, so both now say@vercel/analytics/server. Assertion updated inbrowser.test.ts.x-va-server: '2'is gone. It sat in a branch guarded byhasHeaders, after an unconditionalthrowon!hasHeaders— unreachable, so ingestion never received it. Restore the ternary indispatch()if sending without session headers is ever meant to work.experimentIdover 255 chars is dropped by ingestion with a202. The SDK does not truncate it, same as the prototype.